/**
 * 
 * @author bigk
 * @version 0.8.5
 * 
 * 
 * Copyright (C) 2012  bigktheone@gmail.com

 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 */
package bigk.pluzzdl.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import bigk.pluzzdl.R;

public class ChannelArrayAdapter extends ArrayAdapter<String> {
	private final Context context;
	private final String[] values;

	public ChannelArrayAdapter(Context context, String[] values) {
		super(context, R.layout.channel, values);
		this.context = context;
		this.values = values;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		LayoutInflater inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View rowView = inflater.inflate(R.layout.channel, parent, false);
		TextView textView = (TextView) rowView.findViewById(R.id.label);
		ImageView imageView = (ImageView) rowView.findViewById(R.id.icon);
		textView.setText(values[position]);
		// Change the icon for Windows and iPhone
		String s = values[position];
		if (s.startsWith("la_1ere")) {
			imageView.setImageResource(R.drawable.france_1);
		} else if (s.startsWith("france2")){
			imageView.setImageResource(R.drawable.france_2);
		} else if (s.startsWith("france3")){
			imageView.setImageResource(R.drawable.france_3);
		} else if (s.startsWith("france4")){
			imageView.setImageResource(R.drawable.france_4);
		} else if (s.startsWith("france5")){
			imageView.setImageResource(R.drawable.france_5);
		} else if (s.startsWith("franceo")) {
			imageView.setImageResource(R.drawable.france_o);
		}

		return rowView;
	}
}
